<?php
session_start();
include ("../db/dbcontroller.php");
include ("helper_functions.php");
include ("header.php");
echo "<center><h3> --Peace Buildings-- </h3></center>";


?>

<script type=text/javascript src="countdown.js"></script>
<table width="700px" border="1" cellspacing="0" cellpadding="4"
	high="600px">
	<tr>
		<td colspan="5">
		<h3>Мирные здания</h3>
		</td>
	</tr>
	<tr>
		<td><b>Эмблема</b></td>
		<td><b>Название здания</b></td>
		<td><b>Актуальный Уровень</b></td>
		<td><b>Статус</b></td>
		<td><b>Действие</b></td>
	</tr>




	<?php
	$bname = findWhatIsBuilding($dbc, "peace_buildings");
	$doSomeThing ="строить";

	//alle buttons ausblenden, falls etwas gebaut wird außer dem einen
	//disabled=\"disabled\"

	$query = mysqli_query($dbc, "SELECT bname FROM buildingpeace WHERE townid='$townid'");
	$query = mysqli_fetch_row($query);
	$bname = $query[0];
	if(is_null($bname)){



		echo "\<form method=\"post\">";


		$town_hall = mysqli_query($dbc, "SELECT town_hall FROM peace_buildings WHERE townid='$townid'");
		$town_hall = mysqli_fetch_row($town_hall);
		$town_hall = $town_hall[0];
		echo "<tr><td>image</td><td>Town hall</td><td>Уровень: ".$town_hall.
"<td></td><td><div align=\"center\"><input type=\"submit\" name=\"town_hall\" value=\"построить\" /></div></td>".
"</tr>";


		$query = mysqli_query($dbc, "SELECT money_hall FROM peace_buildings WHERE townid='$townid'");
		$query = mysqli_fetch_row($query);
		$query = $query[0];
		echo "<tr><td>image</td><td>Money hall</td><td>Уровень: ".$query.
"<td></td><td><div align=\"center\"><input type=\"submit\" name=\"money_hall\" value=\"".$doSomeThing."\" /></div></td>".
"</tr>";


		$query = mysqli_query($dbc, "SELECT lighthouse FROM peace_buildings WHERE townid='$townid'");
		$query = mysqli_fetch_row($query);
		$query = $query[0];
		echo "<tr><td>image</td><td>Маяк</td><td>Уровень: ".$query."</tr>";

		$query = mysqli_query($dbc, "SELECT house FROM peace_buildings WHERE townid='$townid'");
		$query = mysqli_fetch_row($query);
		$query = $query[0];
		echo "<tr><td>image</td><td>Дом</td><td>Уровень: ".$query."</tr>";

		$query = mysqli_query($dbc, "SELECT zikurat_sina FROM peace_buildings WHERE townid='$townid'");
		$query = mysqli_fetch_row($query);
		$query = $query[0];
		echo "<tr><td>image</td><td>Зикурат сина</td><td>Уровень: ".$query."</tr>";

		$query = mysqli_query($dbc, "SELECT orositelnyj_kanal FROM peace_buildings WHERE townid='$townid'");
		$query = mysqli_fetch_row($query);
		$query = $query[0];
		echo "<tr><td>image</td><td>Оросительный канал</td><td>Уровень: ".$query."</tr>";

		$query = mysqli_query($dbc, "SELECT port FROM peace_buildings WHERE townid='$townid'");
		$query = mysqli_fetch_row($query);
		$query = $query[0];
		echo "<tr><td>image</td><td>Порт</td><td>Уровень: ".$query."</tr>";


		if($_POST('town_hall')){
			$endtime = 100; //has to be calculated TODO

			$query = mysqli_query($dbc, "UPDATE buildingpeace SET bname=town_hall endtime=$endtime WHERE townid='$townid'");
			$query = mysqli_fetch_row($query);
			$bname = $query[0];
		}


	} else if($bname){


	}

	?>

</table>

	<?php


	?>



	<?php
	include ("footer.php");